package com.xjscrm.console.service.customer.operatePlan.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.operatePlan.GroupWelcomePlanDeviceDto;
import com.xjscrm.console.service.customer.operatePlan.GroupWelcomeBatchService;
import com.xjscrm.console.service.customer.operatePlan.GroupWelcomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GroupWelcomeBatchServiceImpl implements GroupWelcomeBatchService {

    @Autowired
    private GroupWelcomeService groupWelcomeService;
    @Override
    public void batchAddPlanDevice(GroupWelcomePlanDeviceDto groupWelcomePlanDeviceDto) {
        if(groupWelcomePlanDeviceDto.getDeviceUniqueIds()==null||groupWelcomePlanDeviceDto.getDeviceUniqueIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        for (Long deviceUniqueId:groupWelcomePlanDeviceDto.getDeviceUniqueIds()) {
            try {
                groupWelcomePlanDeviceDto.setDeviceUniqueId(deviceUniqueId);
                groupWelcomeService.addPlanDevice(groupWelcomePlanDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    @Override
    public void batchUpdatePlanDevice(GroupWelcomePlanDeviceDto groupWelcomePlanDeviceDto) {
        if(groupWelcomePlanDeviceDto.getIds()==null||groupWelcomePlanDeviceDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        for (Long id:groupWelcomePlanDeviceDto.getIds()) {
            try {
                groupWelcomePlanDeviceDto.setId(id);
                groupWelcomeService.updatePlanDevice(groupWelcomePlanDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    @Override
    public void batchDelPlanDevice(GroupWelcomePlanDeviceDto groupWelcomePlanDeviceDto) {
        if(groupWelcomePlanDeviceDto.getIds()==null||groupWelcomePlanDeviceDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        for (Long id:groupWelcomePlanDeviceDto.getIds()) {
            try {
                groupWelcomePlanDeviceDto.setId(id);
                groupWelcomeService.delPlanDevice(groupWelcomePlanDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
